package com.example.tests;

import java.util.Set;
import static org.junit.Assert.*;
import static org.hamcrest.Matchers.*;

import org.testng.annotations.Test;

public class ContactCreationTest extends TestBase {
	@Test
	public void testValidContactCanBeCreated() throws Exception {
		ContactObject validContact = new ContactObject()
		.setFirstname("antonina").setLastname("Palchikova").setAddress("pereylok 1 novii").setHome("4355").setMobile("43555").setWork("45555").setEmail("rt@frf.frr").setEmail2("rtt@rr.trr").setBday("1").setBmounth("February").setByear("1990").setNew_group("wwwwwwwwww").setAddress2("erfeew").setPhone2("434445");
		Set<ContactObject> oldList = app.getContactHelper().getConacts();
		app.getContactHelper().createContact(validContact);
		Set<ContactObject> newList = app.getContactHelper().getConacts();
		verifyContactAdded(oldList, validContact, newList);
	}
	
	private void verifyContactAdded(Set<ContactObject> oldList,
			ContactObject validContact, Set<ContactObject> newList) {
		assertThat(newList.size(), equalTo(oldList.size()+1));
		validContact.setId("$$$");
		oldList.add(validContact);
		validContact.setId(null);
		assertThat(newList, equalTo(oldList));
		
	}

	@Test
	public void testContactWithEmptyDataCanBeCreated() throws Exception {
		ContactObject emptyDataContact = new ContactObject()
		.setFirstname("").setLastname("").setAddress("").setHome("").setMobile("").setWork("").setEmail("").setEmail2("").setBday("1").setBmounth("March").setByear("").setNew_group("wwwwwwwwww").setAddress2("").setPhone2("");
		app.getContactHelper().createContact(emptyDataContact);
	}
}
